//
//  KeChengNextHeaderView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/17.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "KeChengNextHeaderView.h"
#import "SYRequestAPI+Teach.h"

@implementation KeChengNextHeaderView
- (instancetype)initWithClassID:(NSString *)classID andLessonID:(NSString *)lessonID andFrame:(CGRect)rect{
    if ([super initWithFrame:rect]) {
        self.classID = classID;
        self.lessonId = lessonID;
        [self initSubView];
        [self getCourseDetailRequest];
    }
    return self;
}
//- (instancetype)initWithFrame:(CGRect)frame{
//
//}
- (void)initSubView{
    self.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.titleLabel];
    [self addSubview:self.dangQianJinDuLabel];
    [self addSubview:self.keChengLabel];
    [self addSubview:self.renKeLaoShiLabel];
    [self addSubview:self.nianJiLabel];
    [self addSubview:self.shangKeShiJianLabel];
    [self addSubview:self.keMuLabel];
    [self addSubview:self.zhaoShengRenShuLabel];
    [self addSubview:self.jiaoShiLabel];
    [self addSubview:self.jieYeShiJianLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(@10);
        make.right.equalTo(self.mas_centerX);
        make.height.equalTo(@13);
    }];
    [_dangQianJinDuLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_centerX).offset(10);
        make.top.equalTo(self.titleLabel.mas_top);
        make.right.equalTo(@0).offset(-10);
        make.height.equalTo(@13);
    }];
    [_keChengLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(11);
        make.right.equalTo(self.mas_centerX);
        make.height.equalTo(@12);
    }];
    [_renKeLaoShiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_centerX).offset(10);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(11);
        make.right.equalTo(@0).offset(-10);
        make.height.equalTo(@13);
    }];
    [_nianJiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(self.keChengLabel.mas_bottom).offset(11);
        make.right.equalTo(self.mas_centerX);
        make.height.equalTo(@13);
    }];
    [_shangKeShiJianLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_centerX).offset(10);
        make.top.equalTo(self.keChengLabel.mas_bottom).offset(11);
        make.right.equalTo(@0).offset(10);
        make.height.equalTo(@13);
    }];
    [_keMuLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(self.nianJiLabel.mas_bottom).offset(11);
        make.right.equalTo(self.mas_centerX);
        make.height.equalTo(@13);
    }];
    [_zhaoShengRenShuLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_centerX).offset(10);
        make.top.equalTo(self.nianJiLabel.mas_bottom).offset(11);
        make.right.equalTo(@0).offset(-10);
        make.height.equalTo(@13);
    }];
    [_jiaoShiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(self.keMuLabel.mas_bottom).offset(11);
        make.right.equalTo(self.mas_centerX);
        make.height.equalTo(@13);
    }];
    [_jieYeShiJianLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_centerX).offset(10);
        make.top.equalTo(self.keMuLabel.mas_bottom).offset(11);
        make.right.equalTo(@0).offset(-10);
        make.height.equalTo(@13);
    }];
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(330.5,79.5,140.5,13);
        label.numberOfLines = 0;
        label.text = @"单茹 18 新一 1-D 六A";
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = SELECTEDCOLOR;
        _titleLabel = label;
    }
    return _titleLabel;
}
- (UILabel *)dangQianJinDuLabel{
    if (!_dangQianJinDuLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(330.5,79.5,140.5,13);
        label.numberOfLines = 0;
        label.text = @"当前进度：L25-26 ";
        label.font = [UIFont systemFontOfSize:12];
        label.textColor = TITLECOLOR;
        label.attributedText = [PublickFunctionObject getPriceAttribute:label.text and:SELECTEDCOLOR andChangeBenginString:@"：" andEndString:@"" andSize:12];
        _dangQianJinDuLabel = label;
    }
    return _dangQianJinDuLabel;
}
- (UILabel *)keChengLabel{
    if (!_keChengLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(330,103,178.5,11.5);
        label.numberOfLines = 0;
        label.textColor = TITLECOLOR;
        label.font = [UIFont systemFontOfSize:12];
        label.attributedText = [PublickFunctionObject getPriceAttribute:@"课程名称：音标+新一1期1-34次 " and:SELECTEDCOLOR andChangeBenginString:@"：" andEndString:@"" andSize:12];
        _keChengLabel = label;
    }
    return _keChengLabel;
}
- (UILabel *)renKeLaoShiLabel{
    if (!_renKeLaoShiLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(330,103,178.5,11.5);
        label.numberOfLines = 0;
        label.textColor = TITLECOLOR;
        label.font = [UIFont systemFontOfSize:12];
        label.text = @"任课老师：候园/单茹,李梦迪";
        _renKeLaoShiLabel = label;
    }
    return _renKeLaoShiLabel;
}
- (UILabel *)nianJiLabel{
    if (!_nianJiLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(330,103,178.5,11.5);
        label.numberOfLines = 0;
        label.textColor = TITLECOLOR;
        label.font = [UIFont systemFontOfSize:12];
        label.attributedText = [PublickFunctionObject getPriceAttribute:@"年级：3-6年级 " and:SELECTEDCOLOR andChangeBenginString:@"：" andEndString:@"" andSize:12];
        _nianJiLabel = label;
    }
    return _nianJiLabel;
}
- (UILabel *)shangKeShiJianLabel{
    if (!_shangKeShiJianLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(330,103,178.5,11.5);
        label.numberOfLines = 0;
        label.textColor = TITLECOLOR;
        label.font = [UIFont systemFontOfSize:12];
        label.attributedText = [PublickFunctionObject getPriceAttribute:@"上课时间：周六07:50~09:50 " and:SELECTEDCOLOR andChangeBenginString:@"：" andEndString:@"" andSize:12];
        _shangKeShiJianLabel = label;
    }
    return _shangKeShiJianLabel;
}
- (UILabel *)keMuLabel{
    if (!_keMuLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(330,103,178.5,11.5);
        label.numberOfLines = 0;
        label.textColor = TITLECOLOR;
        label.font = [UIFont systemFontOfSize:12];
        label.attributedText = [PublickFunctionObject getPriceAttribute:@"科目：新概念一/每周一次课 " and:SELECTEDCOLOR andChangeBenginString:@"：" andEndString:@"" andSize:12];
        _keMuLabel = label;
    }
    return _keMuLabel;
}
- (UILabel *)zhaoShengRenShuLabel{
    if (!_zhaoShengRenShuLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(330,103,178.5,11.5);
        label.numberOfLines = 0;
        label.textColor = TITLECOLOR;
        label.font = [UIFont systemFontOfSize:12];
        label.attributedText = [PublickFunctionObject getPriceAttribute:@"招生人数：34/34 " and:SELECTEDCOLOR andChangeBenginString:@"：" andEndString:@"" andSize:12];
        _zhaoShengRenShuLabel = label;
    }
    return _zhaoShengRenShuLabel;
}
- (UILabel *)jiaoShiLabel{
    if (!_jiaoShiLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(330,103,178.5,11.5);
        label.numberOfLines = 0;
        label.textColor = TITLECOLOR;
        label.font = [UIFont systemFontOfSize:12];
        label.attributedText = [PublickFunctionObject getPriceAttribute:@"教室：郑东商业中心校区-3教室 " and:SELECTEDCOLOR andChangeBenginString:@"：" andEndString:@"" andSize:12];
        _jiaoShiLabel = label;
    }
    return _jiaoShiLabel;
}
- (UILabel *)jieYeShiJianLabel{
    if (!_jieYeShiJianLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(330,103,178.5,11.5);
        label.numberOfLines = 0;
        label.textColor = TITLECOLOR;
        label.font = [UIFont systemFontOfSize:12];
        label.attributedText = [PublickFunctionObject getPriceAttribute:@"结业日期：2019-3-30 " and:[UIColor redColor] andChangeBenginString:@"：" andEndString:@"" andSize:12];
        _jieYeShiJianLabel = label;
    }
    return _jieYeShiJianLabel;
}
- (void)setTitleLabelAtrr:(NSString *)content{
    self.titleLabel.text = content;
}
- (void)setDangQianJinDuLabelAtrr:(NSString *)content{
    NSString *string = [NSString stringWithFormat:@"当前进度：%@",content];
    self.dangQianJinDuLabel.attributedText = [PublickFunctionObject getPriceAttribute:string and:[UIColor redColor] andChangeBenginString:@"：" andEndString:@"" andSize:12];
}
- (void)setKeChengLabelAtrr:(NSString *)content{
    
    self.keChengLabel.attributedText = [PublickFunctionObject getPriceAttribute:[NSString stringWithFormat:@"课程名称：%@",content] and:SELECTEDCOLOR andChangeBenginString:@"：" andEndString:@"" andSize:12];
}
- (void)setRenKeLaoShiLabelAtrr:(NSString *)content{
    NSString *string = [NSString stringWithFormat:@"任课老师：%@",content];
    self.renKeLaoShiLabel.text = string;
}
- (void)setNianJiLabelAtrr:(NSString *)content{
    NSString *string = [NSString stringWithFormat:@"年级：%@年级",content];
    self.nianJiLabel.attributedText = [PublickFunctionObject getPriceAttribute:string and:SELECTEDCOLOR andChangeBenginString:@"：" andEndString:@"" andSize:12];
}
- (void)setShangKeShiJianLabelAtrr:(NSString *)content{
    NSString *string = [NSString stringWithFormat:@"上课时间：%@",content];
    self.shangKeShiJianLabel.attributedText = [PublickFunctionObject getPriceAttribute:string and:SELECTEDCOLOR andChangeBenginString:@"：" andEndString:@"" andSize:12];
}
- (void)setKeMuLabelAtrr:(NSString *)content{
    NSString *string = [NSString stringWithFormat:@"科目：%@",content];
    self.keMuLabel.attributedText = [PublickFunctionObject getPriceAttribute:string and:SELECTEDCOLOR andChangeBenginString:@"：" andEndString:@"" andSize:12];
}
- (void)setZhaoShengRenShuLabelAtrr:(NSString *)content{
    NSString *string = [NSString stringWithFormat:@"招生人数：%@",content];
    NSMutableAttributedString *Astring = [[NSMutableAttributedString alloc] initWithString:string attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 12],NSForegroundColorAttributeName: [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0]}];
    [Astring addAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 12]} range:NSMakeRange(0, 4)];
    NSRange range1 = [string rangeOfString:@"/"];
    [Astring addAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 12], NSForegroundColorAttributeName: [UIColor colorWithRed:32/255.0 green:176/255.0 blue:151/255.0 alpha:1.0]} range:NSMakeRange(4, range1.location-1)];
    [Astring addAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 12], NSForegroundColorAttributeName: [UIColor redColor]} range:NSMakeRange(range1.location+1,string.length-range1.location-1)];
    self.zhaoShengRenShuLabel.attributedText = Astring;//[PublickFunctionObject getPriceAttribute:string and:SELECTEDCOLOR andChangeBenginString:@"：" andEndString:@"" andSize:12];
}
- (void)setJiaoShiLabelAtrr:(NSString *)content{
    NSString *string = [NSString stringWithFormat:@"教室：%@",content];
    self.jiaoShiLabel.attributedText = [PublickFunctionObject getPriceAttribute:string and:SELECTEDCOLOR andChangeBenginString:@"：" andEndString:@"" andSize:12];
}
- (void)setJieYeShiJianLabelAtrr:(NSString *)content{
    NSString *string = [NSString stringWithFormat:@"结业日期：%@",content];
    self.jieYeShiJianLabel.attributedText = [PublickFunctionObject getPriceAttribute:string and:[UIColor redColor] andChangeBenginString:@"：" andEndString:@"" andSize:12];
}
#pragma mark - 得到课时详情
- (void)getCourseDetailRequest{
    NSDictionary *parama = @{@"classId":self.classID,
                             @"lessonId":self.lessonId
                             };
//    [MBProgressHUD mj_showMessage:nil toView:self];
    [SYRequestAPI sy_getLessonDetail:parama success:^(id  _Nonnull responseObject) {
        //NSLog(@"得到课程详情 %@",responseObject);
        NSDictionary *dic = [responseObject objectForKey:@"data"][0];
        self->_classDetailModel = [JiaoXueKeChengKeShiDetailModel yy_modelWithJSON:dic];
        [self setTitleLabelAtrr: [NSString stringWithFormat:@"%@ %@",self->_classDetailModel.className,self->_classDetailModel.lessonTitle]];
        //课次
        [self setDangQianJinDuLabelAtrr: [NSString stringWithFormat:@"%@",self->_classDetailModel.lessonTitle]];
        //课程名称
        [self setKeChengLabelAtrr: [NSString stringWithFormat:@"%@",self->_classDetailModel.courseName]];
        //任课老师
        [self setRenKeLaoShiLabelAtrr: [NSString stringWithFormat:@"%@ %@",self->_classDetailModel.className,self->_classDetailModel.lessonTitle]];
        //年级
        [self setNianJiLabelAtrr: [NSString stringWithFormat:@"%@",self->_classDetailModel.className]];
        //上课时间
        [self setShangKeShiJianLabelAtrr: [NSString stringWithFormat:@"%@",self->_classDetailModel.beginDate]];
        //科目
        [self setKeMuLabelAtrr: [NSString stringWithFormat:@"%@",self->_classDetailModel.courseName]];
        //课时人数/招生人数
        [self setZhaoShengRenShuLabelAtrr: [NSString stringWithFormat:@"%@ / %@",self->_classDetailModel.signStudents,self->_classDetailModel.classStudents]];
        //教室
        [self setJiaoShiLabelAtrr: [NSString stringWithFormat:@"%@",self->_classDetailModel.classroom]];
        //结业时间
        [self setJieYeShiJianLabelAtrr: [NSString stringWithFormat:@"%@",self->_classDetailModel.endDate]];
        [MBProgressHUD mj_hideHUDForView:self];
    } fail:^(NSError *error) {
        [MBProgressHUD mj_hideHUDForView:self];
    }];
}
@end
